package com.security.demo.controller;

import com.security.demo.entity.User;
import com.security.demo.service.UserService;
import com.security.demo.utils.CodeUtil;
import com.security.demo.vo.R;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.util.concurrent.TimeUnit;

@RestController
@RequestMapping("/user")
@CrossOrigin
@Slf4j
public class UserController {

    @Autowired
    private UserService userService;


    @GetMapping("/getUserList")
    public R getUserByName(
            @RequestParam(defaultValue = "") String name,
            @RequestParam(defaultValue = "1") int current,
            @RequestParam(defaultValue = "5") int size) {
        log.info("查询用户信息……");
        return userService.getUserList(name, current, size);
    }

    @PostMapping("/addUser")
    public R addUser(@RequestBody User user) {
        log.info("新增用户信息……");
        return userService.addUser(user);
    }

    @PutMapping("/updateUser")
    public R updateUser(@RequestBody User user) {
        log.info("更新用户信息……");
        return userService.updateUser(user);
    }

    @DeleteMapping("/deleteUser")
    public R deleteUser(@RequestParam String name) {
        log.info("删除用户信息……");
        return userService.deleteUser(name);
    }
}
